<?php

class Login extends Controller {

	function Login()
	{
		parent::Controller();	
	}
	
	function index()
	{
		if( !$this->Account->is_guest() ) {
			redirect( '', 'location');
		}

		$error = array();
		if( isset($_POST['submit']) ) {
			$user = $this->input->post('user');
			$password = $this->input->post('password');

			if( $this->Account->login($user, $password) ) {
				redirect('', 'location');
			} else {
				$error = array( 'error'=>'Wrong username or password');
			}
		}
		
		$this->load->view('login.php', $error);
	}

}
